<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      /* 长津湖引用链 */
      function changjinhu() {
        var wql = {
          name: "伍千里",
          age: 34,
          alive: true,
          soldiers: [], //他的兵
        };

        var wwl = {
          name: "伍万里",
          age: 19,
          alive: true,
        };

        var laolei = {
          name: "老雷",
          age: 60,
          alive: true,
        };

        /* 将送入的所有p投入战争 */
        function war(...soldiers) {
          console.log("typeof(soldiers)", typeof soldiers);
          console.log(soldiers);

          // 在战争中老鬼会狗带
          soldiers.forEach(function (s, index) {
            if (s.age >= 50) {
              s.alive = false;
            }
          });
        }

        // 错综复杂的人物关系
        // 吴万里和劳累是五千里的兵
        wql.soldiers.push(laolei, wwl);

        // 将五千里的弟弟赋值为吴万里（引用/地址传递）
        wql.brother = wwl

        // 将吴万里的哥哥赋值为五千里（引用/地址传递）
        wwl.elderBrother = wql

        // 吴万里的boss赋值为老雷（引用/地址传递）
        wwl.boss = laolei

        // 打仗了 老雷有去无回
        war(wql, wwl, laolei);

        /*  */
        console.log(wql.soldiers[0].alive);//
        console.log(wql.soldiers[1].alive);//
        console.log(wql.brother.alive);
        console.log(wwl.elderBrother.alive);
        console.log(wwl.boss.alive);
      }
    //   changjinhu();

      /* 小练习 */
      function practice() {
        function fn(o) {
          o.name = "xp";
          o = { name: "xq" };
        }

        var obj = { name: "xo" };
        fn(obj);
        console.log("obj.name=", obj.name);
      }
      practice()
    </script>
  </body>
</html>
